﻿<%@ Page Language="C#" AutoEventWireup="true" CodeFile="M_right.aspx.cs" Inherits="DMWEB_Pages_Public_M_right" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<%@ Register Src="../UserControl/ChangePageNum.ascx" TagName="ChangePageNum"
    TagPrefix="uc1" %>
<%@ Register TagPrefix="esshs" Namespace="Titan.WebForm" Assembly="WebCalendar" %>
<html xmlns="http://www.w3.org/1999/xhtml" >
<head id="Head1" runat="server">
    <title>用户权限设置</title>
    <style type="text/css">
        table
        {
            border-right: #6666ff 1pt solid; 
            border-top: #6666ff 1pt solid; 
            border-left: #6666ff 1pt solid; 
            border-bottom: #6666ff 1pt solid;
        }
        
        #div_style
        {
	        background:url(../Images/Main/headline.jpg) repeat-x;
	        border:1px #0099CC solid;
	        width:100%;
	        height:10px;
	        text-align:center;
	        padding-top:5px;
            cursor:pointer;
        }
       
        .div_style_con
        {
	        padding-top:10px;
	        text-align:left;
	        margin:0px;
	        padding-left:20px;
	        font-size:12px;
	        width:100%;
	        height:445px;
	        border:1px #0099CC solid;
	        border-width:1px;
	        vertical-align:top
        }
        
        .div_style_con2
        {
	        padding-top:10px;
	        text-align:left;
	        margin:0px;
	        padding-left:20px;
	        font-size:12px;
	        width:95%;
	        height:390px;
	        border:1px #0099CC solid;
	        border-width:1px;
	        vertical-align:top
        }

    </style>
    

    <link href="../CSS/css.css" rel="stylesheet" type="text/css" />
</head>
<body>

<script language="javascript" type="text/javascript">
        function isInteger( str )
        { 
            var regu = /^[-]{0,1}[0-9]{1,}$/;
            return regu.test(str);
        }        
        
        function chkbyid(fid,obj)
        {
            flag = (obj.checked?true:false) ;
            arr = document.all(fid);
            for(var i =0;i<arr.length;i++)
            {
                arr[i].checked=flag;
            }
        }
        
        function chkbyname(obj)
        {
            flag = (obj.checked?true:false) ;
            bid = obj.value;
            document.getElementsByName("q_look_" + bid)[0].checked=flag;
            document.getElementsByName("q_update_" + bid)[0].checked=flag;
            document.getElementsByName("q_insert_" + bid)[0].checked=flag;
            document.getElementsByName("q_delete_" + bid)[0].checked=flag;
        }
        
        function divm()
        {
            clearuserinfo();
            clearqxinfo(1);
            if(div_group.style.display=="none")
            {
                div_group.style.display="block";
                div_user.style.display="none";
                form1.Txt_divstatus.value="div_group";
            }
            else
            {
                div_group.style.display="none";
                div_user.style.display="block";
                form1.Txt_divstatus.value="div_user";
            }
        }
        
        function deletegroup()
        {
            obj = document.getElementById('select_group');
            if(obj.value == "-1")
            {
                alert("请选择要删除的用户组！");return;
            }
            else
            {
                if(confirm("删除用户组，将会影响整个用户组里面的所有用户？继续请按“确定”，否则请按“取消”！(请谨慎用此功能)"))
                {
                    if(confirm("确定要删除此用户组吗？"))
                    {
                        form1.Txt_temp.value = obj.options[obj.selectedIndex].text;
                        form1.Btn_group_delete.click();
                    }
                }
            }
        }
        
        function updategroup()
        {
            if(document.getElementById("select_group").value == "-1")
            {
                alert("请选择用户组！");
                return;
            }
            if(confirm("确定要修改用户组权限吗？"))
            {
                checkqxtotxt();
                form1.Btn_group_modify.click();
            }
        }
        
        function checkqxtotxt()
        {
                arr_look = document.all("q_look");
                arr_update = document.all("q_update");
                arr_insert = document.all("q_insert");
                arr_delete = document.all("q_delete");
                
                qx_look = qx_update = qx_insert = qx_delete = "";
                //look权限
                for( var i =0;i<arr_look.length;i++)
                {
                    if(arr_look[i].checked)
                    {
                        qx_look += "''" + arr_look[i].value + "'',";
                    }
                }
                if(qx_look !="")
                    qx_look = qx_look.substring(0,qx_look.length -1);
                //update权限
                for( var i =0;i<arr_update.length;i++)
                {
                    if(arr_update[i].checked)
                    {
                        qx_update += "''" + arr_update[i].value + "'',";
                    }
                }
                if(qx_update !="")
                    qx_update = qx_update.substring(0,qx_update.length -1);
                //insert权限
                for( var i =0;i<arr_insert.length;i++)
                {
                    if(arr_insert[i].checked)
                    {
                        qx_insert += "''" + arr_insert[i].value + "'',";
                    }
                }
                if(qx_insert !="")
                    qx_insert = qx_insert.substring(0,qx_insert.length -1);
                //delete权限
                for( var i =0;i<arr_delete.length;i++)
                {
                    if(arr_delete[i].checked)
                    {
                        qx_delete += "''" + arr_delete[i].value + "'',";
                    }
                }
                if(qx_delete !="")
                    qx_delete = qx_delete.substring(0,qx_delete.length -1);
                
                sel_group = document.getElementById("select_group");
                
                form1.Txt_temp.value = sel_group.options[sel_group.selectedIndex].text;
                form1.Txt_look.value = qx_look;
                form1.Txt_update.value = qx_update;
                form1.Txt_insert.value = qx_insert;
                form1.Txt_delete.value = qx_delete;
                form1.Txt_content.value = sel_group.selectedIndex;
        }
        
        
        function clearqxinfo(sel)
        {
            flag = (sel==11?true:false);
            chks = document.getElementsByTagName("input");
            for(var i=0;i<chks.length;i++)
            {
                if(chks[i].type=="checkbox")
                {
                    chks[i].checked=false;
                    chks[i].disabled=flag;
                }
            }
            document.getElementById("chk_bslock").disabled=false;
            document.getElementById("chk_csmg").disabled=false;
        }
        
        function groupchange(obj,sel)
        {
            
            clearqxinfo(sel);    
            if((sel == 1) || (sel == 11) )
            {                
                if(obj.value == "-1" )
                    return;
                
                right = obj.value.split('-');
                qx_add = right[0];
                qx_update = right[1];
                qx_insert = right[2];
                qx_delete = right[3]
            }
            else
            {
                qx_add = document.getElementById("Txt_look").value;
                qx_update = document.getElementById("Txt_update").value;
                qx_insert = document.getElementById("Txt_insert").value;
                qx_delete = document.getElementById("Txt_delete").value;
            }
            if(qx_add != "0")
            {
                arr = qx_add.split(',');
                for(var i = 0; i<arr.length;i++)
                {
                    document.getElementsByName("q_look_"+arr[i].substring(1,arr[i].length-1))[0].checked = true;
                }
            }
            
            if(qx_update != "0")
            {
                arr = qx_update.split(',');
                for(var i = 0; i<arr.length;i++)
                {
                    document.getElementsByName("q_update_"+arr[i].substring(1,arr[i].length-1))[0].checked = true;
                }
            }

            if(qx_insert != "0")
            {
                arr = qx_insert.split(',');
                for(var i = 0; i<arr.length;i++)
                {
                    document.getElementsByName("q_insert_"+arr[i].substring(1,arr[i].length-1))[0].checked = true;
                }
            }

            if(qx_delete != "0")
            {
                arr = qx_delete.split(',');
                for(var i = 0; i<arr.length;i++)
                {
                    document.getElementsByName("q_delete_"+arr[i].substring(1,arr[i].length-1))[0].checked = true;
                }
            }
        }
        
        function addgroup()
        {
            obj = document.getElementById("txt_groupname");
            obj.value = obj.value.Trim();
            if(obj.value == "")
            {
                alert("请输入用户组名！");
                return;
            }
            
            groupname = obj.value;
            obj = document.getElementById("select_group");
            for(var i = 0;i<obj.length;i++)
            {
                if(obj.options[i].text == groupname)
                {
                    alert("该用户组名已存在，请重新输入！");
                    document.getElementById("txt_groupname").select();
                    document.getElementById("txt_groupname").focus();
                    return;
                }
            }
            if(confirm("确定要添加该用户组吗？"))
            {
                form1.Txt_temp.value = groupname;
                form1.Btn_group_insert.click();
            }
        }
        
        function clearuserinfo()
        {
            clearqxinfo(1);
            document.getElementById("txt_userid1").value="";
            document.getElementById("txt_userid2").value="";
            document.getElementById("txt_username").value="";
            document.getElementById("select_group2").selectedIndex=0;
            document.getElementById("select_js").selectedIndex = 0;
            document.getElementById("chk_bslock").checked=false;
            document.getElementById("chk_csmg").checked=false;
            document.getElementById("select_bdw").selectedIndex=0;
        }
        
        function adduser()
        {
            if(checkuserinfo())
            {
                if(confirm("确定要添加该用户吗？"))
                {
                    checkqxtotxt();
                    
                    ////用户ID-用户名-本地网-密码-用户组名-角色-bs锁定-cs管理员
                    txt_id = document.getElementById("txt_userid2");
                    txt_name = document.getElementById("txt_username");
                    sel_group = document.getElementById("select_group2");
                    sel_js = document.getElementById("select_js");
                    cks_lock = document.getElementById("chk_bslock");
                    chk_cs = document.getElementById("chk_csmg");
                    sel_bdw = document.getElementById("select_bdw");
                    
                    txt = txt_id.value + ";"
                        + txt_name.value + ";"
                        + sel_bdw.value + ";"
                        + "000000;"
                        + sel_group.options[sel_group.selectedIndex].text + ";"
                        + sel_js.value + ";"
                        + (cks_lock.checked?"1":"0") + ";"
                        + (chk_cs.checked?"1":"0") + ";"
                    form1.Txt_temp.value = txt;
                    form1.Btn_user_add.click();
                    
                }
            }
        }
        
        function checkuserinfo()
        {
            txt_id = document.getElementById("txt_userid2");
            txt_name = document.getElementById("txt_username");
            sel_group = document.getElementById("select_group2");
            sel_js = document.getElementById("select_js");
            cks_lock = document.getElementById("chk_bslock");
            chk_cs = document.getElementById("chk_csmg");
            sel_bdw = document.getElementById("select_bdw");
            
            txt_id.value = txt_id.value.Trim();
            if(txt_id.value == "")
            {
                alert("请输入用户ID！");
                txt_id.focus();
                return false;
            }
            
            if(getuserbyuserid(txt_id.value) != -1)
            {
                alert("该用户ID已存在，请重新输入！");
                txt_id.focus();
                txt_id.select();
                return false;
            }
            
            txt_name.value = txt_name.value.Trim();
            if(txt_name.value == "")
            {
                alert("请输入用户名字！");
                txt_name.focus();
                return false;
            }
            
            if(sel_bdw.selectedIndex == 0)
            {
                alert("请选择用户本地网！");
                sel_bdw.focus();
                return false;
            }
            
            if(sel_group.selectedIndex == 0)
            {
                alert("请选择用户用户组！");
                sel_group.focus();
                return false;
            }
            
            if(sel_js.selectedIndex == 0)
            {
                alert("请选择用户角色！");
                sel_js.focus();
                return false;
            }
            return true;
        }
        
        function changedivuser()
        {
            clearuserinfo();
            clearqxinfo(1);
            obj = document.getElementById("div_user_look");
            obj2 = document.getElementById("div_user_add");
            if(obj2.style.display == 'none')
            {
                obj.style.display = "none";
                obj2.style.display = "block";
            }
            else
            {
                obj.style.display = "block";
                obj2.style.display = "none";
            }
        }
        
        function selectuser()
        {
            clearqxinfo(1);
            var result = window.showModalDialog("user.aspx","","dialogHeight:500px; dialogWidth:465px; toolbar=no, menubar=no, scrollbars=yes, resizable=no, location=no,help = no, status=no, toolbar=no");
            if(result != undefined)
            {
                if(result=="No")
                {
                    //alert("出现异常，请联系管理员！");
                }
                else 
                {
                    arr = result.split("-");
                    document.getElementById("txt_userid1").value = arr[1];
                }
            }
        }
        
        function showuserrightbyid()
        {
            clearqxinfo(1);
            obj = document.getElementById("txt_userid1");
            obj.value = obj.value.Trim();
            if(obj.value == "")
            {
                alert("请输入用户ID！");
                return;
            }
            
            userlist = "<%=user_list %>";
            if(userlist == "")
            {   
                alert("数据库用户表为空，请联系管理员！");
                return;
            }
            
            
            arr = userlist.split(';');
            
            flag = getuserbyuserid(obj.value);
            
            if(flag != -1)
            {
                arr2 = arr[flag].split('-');
                document.getElementById("Txt_look").value = arr2[1];
                document.getElementById("Txt_update").value = arr2[2];
                document.getElementById("Txt_insert").value = arr2[3];
                document.getElementById("Txt_delete").value = arr2[4];
                groupchange("",2);
            }
            else
            {
                alert("该用户ID不存在，请重新输入！");
                obj.select();
                obj.focus();
            }
        }
        
        function getuserbyuserid(userid)
        {
            userlist = "<%=user_list %>";
            arr = userlist.split(';');
            flag = -1;
            for(var i = 0;i<arr.length;i++)
            {
                arr2 = arr[i].split('-');
                if(arr2[0] == userid)
                {
                    flag = i;
                    break;
                }
            }
            return flag;
        }
        
        function testuserid()
        {
            obj = document.getElementById("txt_userid2");
            obj.value = obj.value.Trim();
            if(obj.value == "")
            {
                alert("请输入用户ID！");
                obj.focus();
                return;
            }
            
            flag = getuserbyuserid(obj.value);
            if(flag != -1)
            {
                alert("该用户ID已存在，请重新输入！");
                obj.select();
                obj.focus();
                return;
            }
            else
            {
                alert("恭喜您，该用户ID可用！");
            }
            
        }
        
        function deleteuser()
        {
            obj = document.getElementById("txt_userid1");
            obj.value = obj.value.Trim();
            
            if(obj.value == "")
            {
                alert("请输入用户ID！");
                return;
            }
            
            if(confirm("确定要删除吗？(请谨慎用此功能)"))
            {
                document.getElementById("Txt_temp").value = obj.value;
                form1.Btn_user_delete.click();
            }
        }
        
        function ModifyUserById()
        {
            obj = document.getElementById("txt_userid1");
            obj.value = obj.value.Trim();
            if(obj.value == "")
                return;
            
            userlist = "<%=user_list %>";
            if(userlist == "")
                return;
            
            
            arr = userlist.split(';');
            
            flag = getuserbyuserid(obj.value);
            
            if(flag != -1)
            {
                var result = window.showModalDialog("../../Doughty_cn/ModifyUserById.aspx?userid="+obj.value,"","dialogHeight:545px; dialogWidth:940px; toolbar=no, menubar=no, scrollbars=no, resizable=no, location=no,help = no, status=no, toolbar=no");
                
                if(result != undefined)
                {
                    if(result=="No")
                    {
                        //alert("密码修改出现异常，请联系管理员！");
                    }
                    else 
                    {
                        arr = result.split("-");
                        document.getElementById("Tb_mm").value = arr[1];
                        document.getElementById("Bt_mmsave").click();
                        //alert("密码修改成功！");
                    }
                }
            }
            else
            {
                alert("该用户ID不存在，请重新输入！");
                obj.select();
                obj.focus();
            }
        }
        
String.prototype.Trim = function() { return this.replace(/(^\s*)|(\s*$)/g, ""); }  
String.prototype.LTrim = function() { return this.replace(/(^\s*)/g, ""); }  
String.prototype.RTrim = function() { return this.replace(/(\s*$)/g, ""); } 
    </script>
    
    <form id="form1" runat="server">
        <div id="MainContent">
            <div id="mcTitle" class="tit">权限设置</div>
            <div class="con">
            <div class="btnDiv" style="color: #FF0000">
                <table runat="server" id="tab" style="width:100%;" cellspacing="0" >
                    
                </table>                           
            </div>
            </div>
        </div>
        <div style="display:none">
            <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
            <%----借用Button----%>
            <asp:Button ID="Btn_group_modify" runat="server" Text="组修改" 
                onclick="Btn_group_modify_Click" />
            <asp:Button ID="Btn_group_delete" runat="server" Text="组删除" 
                onclick="Btn_group_delete_Click" style="height: 26px" />
            <asp:Button ID="Btn_group_insert" runat="server" Text="组添加" 
                onclick="Btn_group_insert_Click" />
            <asp:Button ID="Btn_user_delete" runat="server" Text="用户删除" 
                onclick="Btn_user_delete_Click" />
            <asp:Button ID="Btn_user_add" runat="server" Text="用户添加" onclick="Btn_user_add_Click" 
                 />
            
            <%--借用Txt控件--%>
            <asp:TextBox ID="Txt_divstatus" runat="server" Text="div_user"></asp:TextBox>
            <asp:TextBox ID="Txt_content" runat="server" Text=""></asp:TextBox>
            
            <asp:TextBox ID="Txt_look" runat="server" Text=""></asp:TextBox>
            <asp:TextBox ID="Txt_update" runat="server" Text=""></asp:TextBox>
            <asp:TextBox ID="Txt_insert" runat="server" Text=""></asp:TextBox>
            <asp:TextBox ID="Txt_delete" runat="server" Text=""></asp:TextBox>
            <asp:TextBox ID="Txt_temp" runat="server" Text=""></asp:TextBox>
            
        </div>

    </form>
</body>
</html>
<script>
    function showdiv()
    {
        if( form1.Txt_divstatus.value =="div_group" )
        {
                div_group.style.display="block";
                div_user.style.display="none";
                obj = document.getElementById("select_group");
                obj.selectedIndex = form1.Txt_content.value;
                groupchange(obj,1);
        }
        else
        {
                div_group.style.display="none";
                div_user.style.display="block";
        }
    }
    showdiv();
</script>